microbit = codesters.Microbit()
microbit.show_string("hello")
stage.set_background("moon")
sprite = codesters.Sprite("astronaut1")
sprite.move_down(150)
def button_a():
sprite.move_left(50)
microbit.event_button_a(button_a)
def button_b():
sprite.move_right(50)
microbit.event_button_b(button_b)
ball = codesters.Sprite("rock")
ball.set_x_speed(5)
ball.set_y_speed(5)
def collision(sprite, hit_sprite):
my_var = hit_sprite.get_y_speed()
my_var = -my_var + 1
hit_sprite.set_y_speed(5)
sprite.event_collision(collision)
stage.disable_floor()
t = codesters.Teacher()
try:
set_y_speeds = t.find_function("set_y_speed")
tval1 = set_y_speeds[1][1]
except:
tval1 = "DNE"
t1 = TestObjective()
t1.add_success("(my_var)" in tval1, "Great job!")
t1.add_failure("(5)" in tval1, "Did you change the number in set_y_speed from 5 to my_var?")
t1.add_failure("(my_var)" not in tval1, "Did you change the number in set_y_speed from 5 to my_var?")
t1.add_failure(tval1 == "DNE", "Did you delete your set_y_speed command?")
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)